<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/multiselect.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/DateFilter.js"></script>
        <script type="text/javascript" src="../../scripts/form/DDView.js">
        </script>
        <script type="text/javascript" src="../../scripts/form/MultiSelect.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		<script type="text/javascript" src="../../scripts/imageViewer.js"></script>
        <script type="text/javascript">
        var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
        var uiMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.message');
        var messageName = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=com.hilaver.dzmis');
        var plMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.producttimeline.isfinished');
        var sendForm;
        var acUserStore;
        var acUserGrid;

        var ctYesno = new i18nMessage('../../servlet/CodeTableServlet?name=CtYesno');
        var ctClassNameXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtClassName');
        var ctOperationXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtOperation');

        var sysMsgViewerStore;
        var sysMsgViewerGrid;
        var ctYesnoXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtYesno');
        var ctYesnoStore;
        ctYesnoStore = new Ext.data.Store({
            
            reader: new Ext.data.XmlReader({
                record: 'item',
                id: 'code',
                totalRecords: 'itemTotal'
            }, [
            'code', 'description']),
			data: ctYesnoXmlLoader.getXml()
        });

        var isFinishedCombo;
        isFinishedCombo = new Ext.form.ComboBox({
			fieldLabel: uiMessage.get('ui.message.finished') + '?',
			id: 'isFinished',
			name: 'isFinished',
			editable: false,
			valueField: 'code',
		    store: ctYesnoStore,
		    displayField:'description',
		    triggerAction: 'all',
		    emptyText: message.get('message.combo.pleaseselect'),
		    selectOnFocus:true,
		    allowBlank: false,
			mode: 'local',
			anchor: '80%'
		});
        
        var userXMLReader = new Ext.data.XmlReader({
            record: 'item'
        }, [{
            name: 'id',
            mapping: 'id'
        }, {
            name: 'userName',
            mapping: 'userName'
        }, {
            name: 'realName',
            mapping: 'realName'
        }]);
	
        var msgId = getPrarmeterValue(window.location, 'id');
        var startPage = getPrarmeterValue(window.location, 'startPage');
        var isClosed = getPrarmeterValue(window.location, 'isClosed');
        if(isClosed == null && isClosed == ''){
        	isClosed = '02';
        }
        var editCallback = function(){
        	sendForm.getForm().load({
				url:'../../servlet/SysMboxServlet?action=103&id=' + editId, 
				waitMsg:Ext.LoadMask.prototype.msg, 
				success: function(form, action){
					Ext.getCmp('receiverIds').setValue([action.result.data.receiverId]);
					renderMbox(action.result.data.msgId);
					sysMsgViewerStore.reload();
					if(action.result.data.receiverId == top.acUserId){
						isFinishedCombo.disable();
					}else{
						isFinishedCombo.enable();
					}
				},
				failure: function(o){
					messageTip.msg(message.get('message.tip'), message.get('message.load.unsuccessful'));
				}
			});
		}

        var renderMbox = function(msgId){
        	var xmlLoader = new window.xmlLoader('../../servlet/SysMboxServlet?action=11&id=' + msgId);
			var msgRecord = msgXMLReader.readRecords(xmlLoader.getXml()).records[0];
			itemTpl.overwrite('mboxDiv', msgRecord.data);
        }
        var deleteCallback = function(btn){
            if (btn == 'yes') {
                Ext.Ajax.request({
                    url: '../../servlet/SysMboxServlet?action=102&id=' + deleteId,
                    success: function(o){
                        if (o.responseText == 'success') {
                        	sysMsgViewerStore.reload();
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                        }
                        else {
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                        }
                    },
                    failure: function(o){
                        messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                    },
                    params: {
                        foo: 'bar'
                    }
                });
            }
        }

        var msgXMLReader = new Ext.data.XmlReader({
		            record: 'item'
		        }, [{
		            name: 'id',
		            mapping: 'id'
		        }, {
		            name: 'ctClassName',
		            mapping: 'ctClassName'
		        }, {
		            name: 'objId',
		            mapping: 'objId'
		        }, {
		            name: 'parentClassName',
		            mapping: 'parentClassName'
		        }, {
		            name: 'parentObjId',
		            mapping: 'parentObjId'
		        }, {
		            name: 'ctOperation',
		            mapping: 'ctOperation'
		        }, {
		            name: 'modifier',
		            mapping: 'modifier'
		        }, {
		            name: 'modifyDate',
		            mapping: 'modifyDate'
		        }, {
		            name: 'isClosed',
		            mapping: 'isClosed'
		        }, {
		            name: 'message',
		            mapping: 'message'
		        }, {
		            name: 'message',
		            mapping: 'message'
		        }]);

		        var itemTpl = new Ext.XTemplate(
						'<table cellspacing="0" id="the-table" style="width: 100%;"><tbody>',
							'<tr><td style="background:#eeeeee;width: 15%">',
							plMessage.get('ui.producttimeline.isfinished'),
							'</td><td style="width: 15%">{[this.getIsClosed(values.isClosed)]}</td>',
							'<td style="background:#eeeeee;">',
							uiMessage.get('ui.message.operation'),
							'</td><td>{[this.getOperation(values.ctOperation)]}</td>',
							'<td style="background:#eeeeee;">',
							uiMessage.get('ui.message.name'),
							'</td><td>{[this.getMsgName(values.ctClassName)]}</td></tr>',
							'<tr><td style="background:#eeeeee;">',
							message.get('message.edit.date'),
							'</td><td>{modifyDate}</td>',
							'<td style="background:#eeeeee;">',
							uiMessage.get('ui.message.modifier'),
							'</td><td>{modifier}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.go'),
							'</td><td>{[this.getGo(values.ctClassName, values.ObjId, values.parentObjId)]}</td></tr>',
						'</tbody></table>',{
							getOperation:function(value){
								if(value == '01'){
		                    		return String.format('<img src="../../images/icons/add.png" title="' + message.get('message.action.add') + '" />');
		                    	}else if(value == '02'){
		                    		return String.format('<img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" />');	
		                    	}else{
		                    		return String.format('<img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '" />');
		                    	}
							},
							getMsgName:function(value){
								return messageName.get(value);
							},
							getGo: function(ctClassName, objId, parentId){
								var urlObj = getUrl(ctClassName);
		        	    		return String.format('<a href="javascript:parent.addTab(\'{0}\', \'' + urlObj.url  + '\', \'{3}\');void(0);"><img src="../../images/icons/arrow_rotate_clockwise.png" title="{4}" /></a>', urlObj.menuId, objId, parentId, messageName.get(ctClassName),message.get('message.edit.go'));
							},
							getIsClosed: function(value){
								if(value == '01'){
		                    		return String.format('<img src="../../images/icons/tick.png" title="' + message.get('message.list.yes') + '" />');
		                    	}else if(value == '02'){
		                    		return String.format('<img src="../../images/icons/cross.png" title="' + message.get('message.list.no') + '" />');	
		                    	}
							}
						}
			);

		Ext.onReady(function(){
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'side';

            sendForm = new Ext.FormPanel({
		        labelAlign: 'left',
				url: '../../servlet/SysMboxServlet?action=101',
		        frame:true,
		        title: uiMessage.get('ui.message.sendmsg'),
		        bodyStyle:'padding:5px 5px 5px 5px;margin-top: 2px;',
		        width: '100%',
				labelWidth: 75,
				reader: new Ext.data.XmlReader({
			                record: 'item'
			            }, [{
			                name: 'id',
			                mapping: 'id'
			            }, {
			                name: 'q1',
			                mapping: 'q1'
			            }, {
			                name: 'q2',
			                mapping: 'q2'
			            }, {
			                name: 'q3',
			                mapping: 'q3'
			            }, {
			                name: 'a1',
			                mapping: 'a1'
			            }, {
			                name: 'a2',
			                mapping: 'a2'
			            }, {
			                name: 'a3',
			                mapping: 'a3'
			            },{
				            name: 'receiverId',
				            mapping: 'receiverId'
			            },{
							name: 'msgId',
							mapping: 'msgId'
				        },{
							name: 'isFinished',
							mapping: 'isFinished'
				        }]),
				collapsible: true,
		        items: [{
                        id: 'msgId',
                        name: 'msgId',
                        xtype: 'hidden'
                	},{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                	},{
                        id: 'receiverIds',
                        name: 'receiverIds',
                        xtype: 'hidden'
                	},{
						layout: 'column',
						items: [{
							columnWidth:.20,
			                layout: 'form',
							items: [isFinishedCombo]
						},{
							columnWidth:.40,
			                layout: 'form',
							items: [{
		                        fieldLabel: uiMessage.get('ui.message.q') + '1',
		                        name: 'q1',
		                        xtype: 'textarea',
		                        maxLength: 512,
		                        allowBlank:false,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    },{
		                        fieldLabel: uiMessage.get('ui.message.q') + '2',
		                        name: 'q2',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    },{
		                        fieldLabel: uiMessage.get('ui.message.q') + '3',
		                        name: 'q3',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    }]
						},{
							columnWidth:.40,
			                layout: 'form',
							items: [{
		                        fieldLabel: uiMessage.get('ui.message.a') + '1',
		                        name: 'a1',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    },{
		                        fieldLabel: uiMessage.get('ui.message.a') + '2',
		                        name: 'a2',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    },{
		                        fieldLabel: uiMessage.get('ui.message.a') + '3',
		                        name: 'a3',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    }]
						}]
		        	}],
		
		        buttons: [{
		            text: message.get('message.edit.save'),
					handler: function(){
		        		document.getElementsByName('isFinished')[0].value = isFinishedCombo.getValue();
                        if (sendForm.getForm().isValid()) {
                            sendForm.getForm().submit({
                                method: 'post',
                                success: function(form, action){
                                    messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                    sendForm.getForm().reset();
									sysMsgViewerStore.reload();
									Ext.getCmp('receiverIds').disabled = false;
                                },
                                failure: function(form, action){
                                    messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                }
                            });
                        }
                    }
		        },{
					text: message.get('message.edit.reset'),
					handler: function(){
						sendForm.getForm().reset();
						Ext.getCmp('receiverIds').disabled = false;
					}
				}]
		    });
            sendForm.render('sendDiv');
			//Ext.getCmp('receiverIds').setValue([17,16]);

            sysMsgViewerStore = new Ext.data.Store({
                url: '../../servlet/SysMboxServlet?action=106',
                
                reader: new Ext.data.XmlReader({
                    record: 'item',
                    id: 'id',
                    totalRecords: 'itemTotal'
                }, [ 
                'index', {name: 'sysMbox.ctOperation', mapping: 'ctOperation'},{name: 'sysMbox.ctClassName', mapping: 'ctClassName'},{name: 'sysMbox.message', mapping: 'message'},'isFinished', {name: 'sender.realName', mapping: 'senderName'}, {name: 'receiver.realName', mapping: 'receiverName'}, 'createDate', 'modifyDate', 'q1', 'q2', 'q3','a1', 'a2','a3','id']),
                
                remoteSort: true
            }); 

            sysMsgViewerStore.setDefaultSort('modifyDate', 'desc');
            var expander = new Ext.grid.RowExpander({
		        tpl : new Ext.XTemplate(
		        	'<br/><p><b>' + uiMessage.get('ui.message.q') + '1:&nbsp;&nbsp;</b> {q1}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.a') + '1:&nbsp;&nbsp;</b> {a1}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.q') + '2:&nbsp;&nbsp;</b> {q2}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.a') + '2:&nbsp;&nbsp;</b> {a2}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.q') + '3:&nbsp;&nbsp;</b> {q3}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.a') + '3:&nbsp;&nbsp;</b> {a3}</p>'
		        )
		    });
            var filters = new Ext.grid.GridFilters({
				  filters:[
					{type: 'string',  dataIndex: 'sender.realName'},
					{type: 'string',  dataIndex: 'receiver.realName'},
					{type: 'string',  dataIndex: 'sysMbox.message'},
					{type: 'list',  dataIndex: 'sysMbox.ctOperation', options: ctOperationXmlLoader.getCtArray() },
					{type: 'list',  dataIndex: 'sysMbox.ctClassName', options: ctClassNameXmlLoader.getCtArray() },
					{type: 'date',  dataIndex: 'createDate'},
					{type: 'date',  dataIndex: 'modifyDate'},
					{type: 'list',  dataIndex: 'isFinished',options: ctYesno.getCtArray()}
			]});
			sysMsgViewerGrid = new Ext.grid.GridPanel({
                title: uiMessage.get('ui.message.sendlist'),
                store: sysMsgViewerStore,
                plugins: [expander,filters],
				stripeRows: true,
                height: 360,
                columns: [expander,{
                    header: message.get('message.list.id'),
                    width: 30,
                    dataIndex: 'index'
                },{
                    header: uiMessage.get('ui.message.operation'),
                    dataIndex: 'sysMbox.ctOperation',
                    width: 30,
                    sortable: true,
                    renderer: function(value, metaData, record){
                    	if(value == '01'){
                    		return String.format('<img src="../../images/icons/add.png" title="' + message.get('message.action.add') + '" />');
                    	}else if(value == '02'){
                    		return String.format('<img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" />');	
                    	}else{
                    		return String.format('<img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '" />');
                    	}
                	}
                },  {
                    header: uiMessage.get('ui.message.name'),
                    dataIndex: 'sysMbox.ctClassName',
                    sortable: true,
        	        renderer: function(value, metaData, record){
        	    		return messageName.get(value);
        	        }
                }, {
                    header: uiMessage.get('ui.message.message'),
                    dataIndex: 'sysMbox.message',
                    sortable: true,
                    renderer: function(value, metaData, record){
                	if(value == 'null'){
                		return '';
                	}
                	return value;
            	}
                },{
                    header: uiMessage.get('ui.message.sender'),
                    sortable: true,
                    dataIndex: 'sender.realName'
                },{
                    header: uiMessage.get('ui.message.recevier'),
                    sortable: true,
                    dataIndex: 'receiver.realName'
                },{
                    header: uiMessage.get('ui.message.createdate'),
                    sortable: true,
                    dataIndex: 'createDate'
                },{
                    header: uiMessage.get('ui.message.modifydate'),
                    sortable: true,
                    dataIndex: 'modifyDate',
                    renderer: function(value, metaData, record){
	    	    		if(record.data.modifyDate == record.data.createDate){
	        	    		return '';
	    	    		}else{
	    	    			return record.data.modifyDate;
	        	    	}
	    	        }
                },{
                    header: uiMessage.get('ui.message.finished'),
                    sortable: true,
                    dataIndex: 'isFinished',
                    width: 30,
                    renderer: function(value, metaData, record){
	    	    		if(value == '01'){
	        	    		return String.format('<img src="../../images/icons/tick.png" title="' + message.get('message.list.yes') + '" />');
	    	    		}else{
	    	    			return String.format('<img src="../../images/icons/cross.png" title="' + message.get('message.list.no') + '" />');
	        	    	}
	    	        }
                },{
                    header: message.get('message.list.eidt'),
                    dataIndex: 'id',
                    width: 30,
                    renderer: renderEdit
                },{
                    header: message.get('message.list.delete'),
                    dataIndex: 'id',
                    width: 30,
                    renderer: renderDelete
                }],
                viewConfig: {
                    forceFit: true
                },
                loadMask: true,
                renderTo: 'sendListDiv',
                bbar: new Ext.PagingToolbar({
                    pageSize: 20,
                    store: sysMsgViewerStore,
                    displayInfo: true
                })
            });
			
			sysMsgViewerStore.load({
                params: {
	                start: 0,
	                limit: 20
	            }
	        });
			
			function renderEdit(value, p, record){
                return String.format('<a href="javascript: editItem(editCallback, {0});"><img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" /></a>', record.id);
            }
            
            function renderDelete(value, p, record){
                return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '"/></a>', record.id);
            }
			
            
		});
		
       
        </script>
	</head>
	<body>
		<div id="mboxDiv">
        </div>
        <div id="sendDiv" style="margin-top: 5px;">
        </div>
        <div id="sendListDiv" style="margin-top: 5px;">
        </div>
	</body>
</html>